home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 014 / bacopy.arc / BACOPY.DOC < prev   
Encoding:
Text File  |  1985-07-18  |  9.8 KB  |  162 lines

  1.                    End Big Blue's Backup Blues
  2.    (PC Magazine Vol 4 No 17 August 20, 1985 by John Dickinson)
  3.  
  4.     Backups should be made on a regular basis whether you work
  5. with a floppy disk-based PC or with a hard disk machine such as in
  6. the XT or enhanced AT.  Unfortunately, PC-DOS doesn't make the job
  7. very easy.  Floppy disk users can make use of the DISKCOPY command
  8. to make backup copies of their disks.  Users with hard disks are
  9. stuck with the PC-DOS BACKUP command.  This latter makes copies of
  10. files that cannot be used until after they have been returned to
  11. the original disk by using the RESTORE command.
  12.     Neither command works very quickly, so many users prefer
  13. the COPY command as a faster alternative.  With COPY they can make
  14. discretionary incremental backups of only the files that have been
  15. changed since the last backup was made.  For hard disk users, COPY
  16. offers the added benefits of quick restoration, the ability to peek
  17. at the last version of a file, and the ability to use the file
  18. directly on another system should yours go down because of a hard
  19. disk failure -- facilities you lose with the BACKUP command.  (Note
  20. that there is no good substitute in the standard PC-DOS environment
  21. for BACKUP and RESTORE when it comes to making periodic, say, weekly
  22. backups of your entire hard disk.)
  23.     There are two problems with using COPY as a general backup
  24. utility.  First, the task of deciding which files to back up is left
  25. to you.  If you're like me, that means you copy all the files in a
  26. directory or on a disk rather than chance missing one you forgot you
  27. had changed.  That can take a long time.  The other problem is that
  28. if you're copying a large directory from a hard disk to a floppy
  29. disk, the target floppy can get full if you copy all the files to it.
  30. Deciding which files did and did not get copied to the first disk and
  31. then copying each remaining one to a second disk is a major annoyance.
  32.     All that's really needed to cure both of these ills is a 
  33. command that's slightly more intelligent than COPY, but without all 
  34. the sophistication of BACKUP.  The command should copy only the files
  35. that have been altered onto a target floppy disk, and should be able
  36. to continue on to a new disk when the original fills up.  Fortunately,
  37. it isn't difficult to create an assembly language command called
  38. BACopy that does the trick.
  39.     BACopy works very much like the COPY command, even down to
  40. using almost the same source-to-target syntax:
  41.         [d:][path]filename[.ext] [d:] [path]
  42.     Like COPY, BACopy allows making backup copies of files from
  43. any source disk and directory to any target disk and directory.  This
  44. lets you make spare copies on the same disk in different directories,
  45. for example.  It also allows PC-DOS wildcard notation to be freely
  46. used.
  47.     The only exception to COPY's syntax is that BACopy does not
  48. allow renaming the file during the copy process.  To do so would make
  49. the backup strategy needlessly confusing.  (You could, of course, fool
  50. BACopy into making extra copies by renaming files on the target disk
  51. when it's through working, but that's up to you.)
  52.     BACopy makes more important exceptions to COPY's rules when
  53. it comes to how the program works.  BACopy checks for the existence
  54. of each file you requested it to copy on the target disk.  If the 
  55. file is already on the target disk, however, BACopy compares the save
  56. date and time of the source and target files and only copies the 
  57. original to the target if the original file is newer.
  58.     The other exception to COPY's procedure is that BACopy doesn't
  59. quit if you run out of disk space.  It recovers from a target disk-full
  60. error by asking you to insert another one so it can continue with its
  61. work.
  62.     BACopy does not disturb the archive bit in the source file's
  63. directory.  This bit is used to indicate whether or not a backup has
  64. been made.  As it was designed to be, changing the archive bit remains
  65. the prerogative of the BACKUP command.  BACopy's backup strategy does
  66. depend on you to set your PC's clock to the correct time and date when
  67. you start your system, of course.  If you do that, your file's time
  68. and date stamps will correctly indicate if and when you have modified
  69. your files.
  70.     The source code for BAC.COM is written in assembly language,
  71. and the full, commented listing is 7 pages long.  You can obtain 
  72. BACopy in its assembler version by downloading it from PC Magazine's
  73. Interactive Reader Service (212-696-0360).  The code will assemble
  74. using either IBM's or Microsoft's assembler.  After linking it with
  75. the PC-DOS LINK command, make sure to convert it to a .COM file
  76. using EXE2BIN.  The BACOPY.BAS program automatically creates BAC.COM.
  77.     Like most programs, BACopy starts out by parsing the command
  78. line.  Here we need to know the source disk, directory and filename
  79. (including extension, if present), as well as the target disk and
  80. directory.  The code in BACopy will look familiar to those of you
  81. who worked with the REDirect program (PC Magazine, Volume 4 Number 4).
  82. That's no surprise, since it's the same, and you can just copy it into
  83. your new file if you have a working copy of REDirect's source code.
  84.     PC-DOS function calls 4EH and 4FH are used to find the source
  85. file: This technique is what allows wildcards to be used.  As each 
  86. file is found, the target file is looked for by using function call
  87. 4FH.  If the target is not found, BACopy goes directly to the routine
  88. for opening the source file, creating the target and copying the
  89. source file into into.
  90.     If the target file exists, the save dates and times of the
  91. two files are compared.  I do this by looking at the words at byte
  92. 24 (date) and byte 22 (time) in the Disk Transfer Area (DTA) for each
  93. file.  (A PC-DOS function call, 57H, would do this, but it takes
  94. longer than my procedure because the files have to be opened first.)
  95. If the date of the target file is the same or newer than that of the
  96. source file, BACopy won't make a new copy.  In this case a utility
  97. subroutine is called to make sure any open files are closed.  The
  98. program then goes on to look at the next file.
  99.     When a target file must be created, the source file is
  100. opened, and a file handle is assigned by calling PC-DOS function
  101. call 3DH.  The target file is then created by using function 3CH.
  102. A handle for the target is assigned to PC-DOS when 3CH is called.
  103. The reason BACopy creates the target, rather than opens it, is two-
  104. fold.  First, the same code works whether or not the target file
  105. exists, and second, the file size in the directory entry will be
  106. correctly updated when the new copy of the file has fewer bytes
  107. than the old version.
  108.     Blocks of data are then moved from the source file into
  109. memory and then to the target file.  The size of each block is
  110. determined by the distance between the top of available memory
  111. (which is just below the stack area of a .COM file) and the end of
  112. the program.  The current versino of BACopy yields a BLKSIZE of
  113. about 62K bytes, which is about the size of the memory buffer used
  114. by the COPY command.
  115.     Using function call 3FH, each read request asks PC-DOS to
  116. read the BLKSIZE bytes.  If fewer are returned than expected (this
  117. can be determined by looking at the AX register when Interrupt 21H
  118. returns), the last available block of data has been read.  Unless
  119. no bytes were read, the write request (PC-DOS function call 40H)
  120. asks that the same number of bytes read from the source file to
  121. the target file.
  122.     If the requested number of bytes was written, so the
  123. program has not reached the last block, BACopy returns and continues
  124. working.  If it hits the last block of data, BACopy jumpts to the
  125. clean-up routines.  There it uses PC-DOS function call 57H to get
  126. the source file's time and date stamp and apply it to the target
  127. file (writing into the DTA doesn't do the trick, though you might
  128. think it would).  If BACopy didn't do it this way, the target file
  129. would have the current time and date in its directory when it gets
  130. closed, and part of BACopy's design purpose would be defeated.
  131. Again, this exactly parallels the COPY command.
  132.     If the requested number of bytes was not written, it means
  133. that the target disk is full.  Rather than just quit, however, as
  134. the COPY command does, BACopy provides a recovery routine.  It
  135. closes all files, erases the target file as it exists so far, and
  136. requests that you insert a new disk in the target disk drive.  The
  137. program will not proceed further until you press the Enter key,
  138. and it will stop if you press the Ctrl-Break combination instead.
  139. While this technique is not nearly as clever as BACKUP's trick of
  140. spanning files across disks, it will do just fine for most users
  141. who want to make incremental backups.
  142.     If, at the end of everything, BACopy finds out it didn't
  143. modify or create any target files, it tells you there was nothing
  144. to back up.  That message will only appear if all source files
  145. exist on the target disk and directory and are the same dates or
  146. older than the target files.
  147.     I've been using BACopy on a daily basis for some time now,
  148. and have found it most helpful.  It's a fraction of a second slower
  149. per file than COPY when you're running it for one file, but it saves
  150. so much time as you update your overall group of files that this
  151. slight performance penalty is well worth it.  Most of the batch
  152. files I use to move about my hard disk and Bernoulli Box know how
  153. to run BACopy at appropriate moments.  If a target disk isn't ready,
  154. PC-DOS tells you about it -- BACopy doesn't have to worry.
  155.     Depending on which directory and disk I'm using, an ordinary
  156. floppy, the AT's high density floppy, or one of the Bernoulli Box
  157. disks is BACopy's target.  All three work fine with BACopy, and the
  158. higher-density disks make it reasonable to have floppy disk
  159. directories to house your backups, a feature unsupported by the
  160. BACKUP command.
  161.  
  162.